import request from '@/utils/request'

// 获取商品列表（分页查询）
export const getProductList = (data) => {
  return request({
    url: '/product/list',
    method: 'post',
    data
  })
}

// 获取商品详情
export const getProductDetail = (id) => {
  return request({
    url: `/product/${id}`,
    method: 'get'
  })
}

// 添加商品
export const addProduct = (data) => {
  return request({
    url: '/product',
    method: 'post',
    data
  })
}

// 更新商品
export const updateProduct = (data) => {
  return request({
    url: '/product',
    method: 'put',
    data
  })
}

// 删除商品
export const deleteProduct = (id) => {
  return request({
    url: `/product/${id}`,
    method: 'delete'
  })
}

// 批量删除商品
export const batchDeleteProducts = (ids) => {
  return request({
    url: '/product/batch',
    method: 'delete',
    data: ids
  })
}

// 获取热销商品
export const getHotProducts = (limit = 10) => {
  return request({
    url: '/product/hot',
    method: 'get',
    params: { limit }
  })
}

// 获取库存预警商品
export const getStockAlertProducts = () => {
  return request({
    url: '/product/stock-alert',
    method: 'get'
  })
}

// 获取商品分类列表
export const getCategoryList = () => {
  return request({
    url: '/category/list',
    method: 'get'
  })
}

// 获取分类树
export const getCategoryTree = () => {
  return request({
    url: '/category/tree',
    method: 'get'
  })
}

// 搜索商品（通过名称或条形码）
export const searchProduct = (keyword) => {
  return request({
    url: '/product/list',
    method: 'post',
    data: {
      name: keyword,
      barcode: keyword,
      page: 1,
      pageSize: 20,
      status: 1  // 只搜索上架商品
    }
  })
}











